<script setup>
import * as echarts from 'echarts';
import { ref, nextTick } from 'vue'
defineProps({
  msg: String,
})

const count = ref(0)
nextTick(() => {
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

option = {
  title: {
    text: '网络安全宣传周 - 用户参与数据统计',
    subtext: '数据统计时间：2025年9月15日-21日',
    left: 'center',
    top: '2%',
    textStyle: {
      color: '#333333',
      fontSize: 16,
      fontWeight: '500'
    },
    subtextStyle: {
      color: '#999999',
      fontSize: 11
    }
  },
  backgroundColor: '#ffffff',
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(15, 23, 42, 0.9)',
    borderColor: '#3b82f6',
    borderWidth: 1,
    textStyle: {
      color: '#e2e8f0'
    },
    axisPointer: {
      type: 'cross',
      crossStyle: {
        color: '#3b82f6'
      },
      lineStyle: {
        color: '#3b82f6',
        type: 'dashed'
      }
    }
  },
  grid: {
    top: '20%',
    bottom: '10%',
    left: '8%',
    right: '8%'
  },
  toolbox: {
    feature: {
      dataView: { show: true, readOnly: false },
      magicType: { show: true, type: ['line', 'bar'] },
      restore: { show: true },
      saveAsImage: { show: true }
    }
  },
  legend: {
    data: ['线下扫码', 'app跳转', '长按识别', '总人数'],
    top: '12%',
    left: 'center',
    textStyle: {
      color: '#666666',
      fontSize: 13
    },
    itemWidth: 12,
    itemHeight: 12
  },
  xAxis: [
    {
      type: 'category',
      data: ['9-15', '9-16', '9-17', '9-18', '9-19', '9-20', '9-21'],
      axisLine: {
        lineStyle: {
          color: '#475569'
        }
      },
      axisTick: {
        lineStyle: {
          color: '#64748b'
        }
      },
      axisLabel: {
        color: '#334155',
        fontSize: 11
      },
      axisPointer: {
        type: 'shadow',
        shadowStyle: {
          color: 'rgba(59, 130, 246, 0.1)'
        }
      }
    }
  ],
  yAxis: [
    {
      type: 'value',
      name: '每日新增',
      nameTextStyle: {
        color: '#1e40af',
        fontSize: 12
      },
      min: 0,
      max: 30000,
      interval: 5000,
      axisLine: {
        lineStyle: {
          color: '#64748b'
        }
      },
      axisTick: {
        lineStyle: {
          color: '#64748b'
        }
      },
      axisLabel: {
        formatter: '{value} 人',
        color: '#334155',
        fontSize: 10
      },
      splitLine: {
        lineStyle: {
          color: '#e2e8f0',
          type: 'dashed'
        }
      }
    },
    {
      type: 'value',
      name: '累计总数',
      nameTextStyle: {
        color: '#dc2626',
        fontSize: 12
      },
      min: 0,
      max: 85000,
      interval: 15000,
      axisLine: {
        lineStyle: {
          color: '#64748b'
        }
      },
      axisTick: {
        lineStyle: {
          color: '#64748b'
        }
      },
      axisLabel: {
        formatter: '{value} 人',
        color: '#334155',
        fontSize: 10
      },
      splitLine: {
        show: false
      }
    }
  ],
  series: [
    {
      name: '线下扫码',
      type: 'bar',
      barWidth: '20%',
      itemStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [{
            offset: 0, color: '#3b82f6'
          }, {
            offset: 1, color: '#1d4ed8'
          }]
        },
        borderRadius: [4, 4, 0, 0]
      },
      tooltip: {
        valueFormatter: function (value) {
          return value + ' 人';
        }
      },
      data: [
        3500, 9500, 10800, 9800, 0, 0, 0
      ]
    },
    {
      name: 'app跳转',
      type: 'bar',
      barWidth: '20%',
      itemStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [{
            offset: 0, color: '#10b981'
          }, {
            offset: 1, color: '#059669'
          }]
        },
        borderRadius: [4, 4, 0, 0]
      },
      tooltip: {
        valueFormatter: function (value) {
          return value + ' 人';
        }
      },
      data: [
        5200, 10800, 9800, 9200, 0, 0, 0
      ]
    },
    {
      name: '长按识别',
      type: 'bar',
      barWidth: '20%',
      itemStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [{
            offset: 0, color: '#f59e0b'
          }, {
            offset: 1, color: '#d97706'
          }]
        },
        borderRadius: [4, 4, 0, 0]
      },
      tooltip: {
        valueFormatter: function (value) {
          return value + ' 人';
        }
      },
      data: [
        800, 2800, 2200, 1800, 0, 0, 0
      ]
    },
    {
      name: '总人数',
      type: 'line',
      yAxisIndex: 1,
      smooth: true,
      lineStyle: {
        color: '#dc2626',
        width: 3,
        shadowColor: 'rgba(220, 38, 38, 0.3)',
        shadowBlur: 10
      },
      itemStyle: {
        color: '#dc2626',
        borderColor: '#fff',
        borderWidth: 2,
        shadowColor: 'rgba(220, 38, 38, 0.3)',
        shadowBlur: 5
      },
      symbol: 'circle',
      symbolSize: 8,
      tooltip: {
        valueFormatter: function (value) {
          return value + ' 人';
        }
      },
      data: [9500, 32600, 55400, 75200, 75200, 75200, 75200]
    }
  ]
};

option && myChart.setOption(option);
})
</script>

<template>
  <div class="cus-app">
    <div class="chart-container">
      <div id="main"></div>
    </div>
  </div>
</template>

<style scoped>
.cus-app {
  width: 100vw;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 40px 20px;
  margin: 0;
  font-family: 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.chart-container {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#main {
  width: 1000px;
  height: 550px;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 20px;
  box-sizing: border-box;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  #main {
    width: 90vw;
    height: 550px;
  }
  
  .main-title {
    font-size: 28px;
  }
  
  .chart-container {
    padding: 20px 10px;
  }
}

@media (max-width: 768px) {
  #main {
    width: 95vw;
    height: 400px;
  }
  
  .main-title {
    font-size: 24px;
  }
  
  .security-icon {
    font-size: 36px;
  }
}
</style>
